/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * formPeminjaman.java
 *
 * Created on Oct 12, 2011, 8:47:24 PM
 */
package modul.pencatatan.datapeminjaman;

import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.text.DecimalFormat;
import java.text.DecimalFormatSymbols;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JOptionPane;
import model.util.conn.DataBaseConnection;

/**
 *
 * @author Pinds
 */
public class formPeminjaman extends javax.swing.JInternalFrame {

    public formPeminjaman(String iD) {
        this.initComponents();
        this.setTitle("Peminjaman");
        this.idPeminjamComboBox();
        tabelModel = new detailPeminjamanTabelModel();
        tbDetailPeminjaman.setModel(tabelModel);
        id = iD;
    }

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jPanel2 = new javax.swing.JPanel();
        labelFormPeminjaman = new javax.swing.JLabel();
        jPanel3 = new javax.swing.JPanel();
        tAlamat = new javax.swing.JTextField();
        tTelepon = new javax.swing.JTextField();
        jLabel1 = new javax.swing.JLabel();
        cbIdPeminjam = new javax.swing.JComboBox();
        tNama = new javax.swing.JTextField();
        jPanel4 = new javax.swing.JPanel();
        jLabel2 = new javax.swing.JLabel();
        tNoPeminjaman = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        dcTanggalPinjam = new com.toedter.calendar.JDateChooser();
        jLabel4 = new javax.swing.JLabel();
        dcTanggalKembali = new com.toedter.calendar.JDateChooser();
        jLabel5 = new javax.swing.JLabel();
        cbJaminan = new javax.swing.JComboBox();
        jPanel5 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        tbDetailPeminjaman = new javax.swing.JTable();
        jLabel9 = new javax.swing.JLabel();
        tKodeDVD = new javax.swing.JTextField();
        buttonTambahList = new javax.swing.JButton();
        tStock = new javax.swing.JTextField();
        tDipinjam = new javax.swing.JTextField();
        tHarga = new javax.swing.JTextField();
        tJudulFilm = new javax.swing.JTextField();
        jPanel6 = new javax.swing.JPanel();
        tTotal = new javax.swing.JTextField();
        jLabel6 = new javax.swing.JLabel();
        buttonTutup = new javax.swing.JButton();
        buttonSimpan = new javax.swing.JButton();
        buttonCetakNota = new javax.swing.JButton();
        bBaru = new javax.swing.JButton();

        setFrameIcon(new javax.swing.ImageIcon(getClass().getResource("/modul/util/image/cart_put.png"))); // NOI18N

        jPanel2.setBackground(new java.awt.Color(204, 255, 204));

        labelFormPeminjaman.setFont(new java.awt.Font("Tahoma", 1, 18));
        labelFormPeminjaman.setText("FORM PEMINJAMAN DVD/ VCD");

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGap(149, 149, 149)
                .addComponent(labelFormPeminjaman, javax.swing.GroupLayout.PREFERRED_SIZE, 299, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(138, Short.MAX_VALUE))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(labelFormPeminjaman)
                .addContainerGap(20, Short.MAX_VALUE))
        );

        jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder("Identitas Peminjam"));

        tAlamat.setEnabled(false);

        tTelepon.setEnabled(false);

        jLabel1.setText("ID Peminjam");

        cbIdPeminjam.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
        cbIdPeminjam.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cbIdPeminjamActionPerformed(evt);
            }
        });

        tNama.setEnabled(false);

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addComponent(jLabel1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(cbIdPeminjam, javax.swing.GroupLayout.PREFERRED_SIZE, 92, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(tNama, javax.swing.GroupLayout.DEFAULT_SIZE, 239, Short.MAX_VALUE)
                    .addComponent(tTelepon, javax.swing.GroupLayout.DEFAULT_SIZE, 239, Short.MAX_VALUE)
                    .addComponent(tAlamat, javax.swing.GroupLayout.DEFAULT_SIZE, 239, Short.MAX_VALUE))
                .addContainerGap())
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addGap(11, 11, 11)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(cbIdPeminjam, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(3, 3, 3)
                .addComponent(tNama, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(tTelepon, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(tAlamat, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jPanel4.setBorder(javax.swing.BorderFactory.createTitledBorder("Transaksi Peminjaman"));

        jLabel2.setText("No. Peminjaman");

        tNoPeminjaman.setEnabled(false);

        jLabel3.setText("Tanggal Pinjam");

        dcTanggalPinjam.setDateFormatString("yyyy-MM-dd");

        jLabel4.setText("Tanggal Kembali");

        dcTanggalKembali.setDateFormatString("yyyy-MM-dd");

        jLabel5.setText("Jaminan");

        cbJaminan.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "KTP", "SIM", "KTM" }));

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel5, javax.swing.GroupLayout.DEFAULT_SIZE, 77, Short.MAX_VALUE)
                    .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                        .addComponent(jLabel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jLabel3)
                        .addComponent(jLabel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                .addGap(33, 33, 33)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(dcTanggalKembali, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(dcTanggalPinjam, javax.swing.GroupLayout.DEFAULT_SIZE, 118, Short.MAX_VALUE)
                    .addComponent(cbJaminan, javax.swing.GroupLayout.PREFERRED_SIZE, 67, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(tNoPeminjaman))
                .addContainerGap(45, Short.MAX_VALUE))
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(tNoPeminjaman, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel3)
                    .addComponent(dcTanggalPinjam, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel4)
                    .addComponent(dcTanggalKembali, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel5)
                    .addComponent(cbJaminan, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(19, Short.MAX_VALUE))
        );

        jPanel5.setBorder(javax.swing.BorderFactory.createTitledBorder("Detail Peminjaman"));

        tbDetailPeminjaman.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null}
            },
            new String [] {
                "Kode DVD/VCD", "Judul Film", "Harga"
            }
        ));
        jScrollPane1.setViewportView(tbDetailPeminjaman);

        jLabel9.setText("Kode DVD/VCD :");

        tKodeDVD.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                tKodeDVDKeyPressed(evt);
            }
        });

        buttonTambahList.setText("Tambah");
        buttonTambahList.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                buttonTambahListActionPerformed(evt);
            }
        });

        tStock.setEnabled(false);

        tDipinjam.setEnabled(false);

        tHarga.setEnabled(false);

        tJudulFilm.setEnabled(false);

        javax.swing.GroupLayout jPanel5Layout = new javax.swing.GroupLayout(jPanel5);
        jPanel5.setLayout(jPanel5Layout);
        jPanel5Layout.setHorizontalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel5Layout.createSequentialGroup()
                        .addComponent(jLabel9)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(tKodeDVD, javax.swing.GroupLayout.PREFERRED_SIZE, 117, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                        .addGroup(jPanel5Layout.createSequentialGroup()
                            .addComponent(tJudulFilm)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                            .addComponent(tHarga, javax.swing.GroupLayout.PREFERRED_SIZE, 87, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(tStock, javax.swing.GroupLayout.PREFERRED_SIZE, 72, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(tDipinjam, javax.swing.GroupLayout.PREFERRED_SIZE, 79, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(buttonTambahList))
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 542, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(12, Short.MAX_VALUE))
        );
        jPanel5Layout.setVerticalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel5Layout.createSequentialGroup()
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(jPanel5Layout.createSequentialGroup()
                        .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel9)
                            .addComponent(tKodeDVD, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(26, 26, 26))
                    .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(buttonTambahList)
                        .addComponent(tDipinjam, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(tStock, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(tHarga, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(tJudulFilm, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 141, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jPanel6.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        tTotal.setFont(new java.awt.Font("Tahoma", 1, 24));
        tTotal.setEnabled(false);

        jLabel6.setFont(new java.awt.Font("Tahoma", 1, 24));
        jLabel6.setText("Sub Total");

        javax.swing.GroupLayout jPanel6Layout = new javax.swing.GroupLayout(jPanel6);
        jPanel6.setLayout(jPanel6Layout);
        jPanel6Layout.setHorizontalGroup(
            jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel6Layout.createSequentialGroup()
                .addContainerGap(192, Short.MAX_VALUE)
                .addComponent(jLabel6, javax.swing.GroupLayout.PREFERRED_SIZE, 132, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(tTotal, javax.swing.GroupLayout.PREFERRED_SIZE, 224, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );
        jPanel6Layout.setVerticalGroup(
            jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel6Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(tTotal, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel6))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        buttonTutup.setText("Tutup");
        buttonTutup.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                buttonTutupActionPerformed(evt);
            }
        });

        buttonSimpan.setText("Simpan");
        buttonSimpan.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                buttonSimpanActionPerformed(evt);
            }
        });

        buttonCetakNota.setText("Cetak Nota");
        buttonCetakNota.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                buttonCetakNotaActionPerformed(evt);
            }
        });

        bBaru.setIcon(new javax.swing.ImageIcon(getClass().getResource("/modul/util/image/new.png"))); // NOI18N
        bBaru.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bBaruActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel6, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(bBaru, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 250, Short.MAX_VALUE)
                .addComponent(buttonCetakNota, javax.swing.GroupLayout.PREFERRED_SIZE, 86, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(buttonSimpan, javax.swing.GroupLayout.PREFERRED_SIZE, 83, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(buttonTutup, javax.swing.GroupLayout.PREFERRED_SIZE, 89, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel5, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                        .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(buttonTutup, javax.swing.GroupLayout.PREFERRED_SIZE, 24, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(buttonSimpan, javax.swing.GroupLayout.PREFERRED_SIZE, 24, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(buttonCetakNota, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(bBaru))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    private void idPeminjamComboBox() {
        try {
            Statement st = DataBaseConnection.getConnection().createStatement();
            String sql = "select ID_Peminjam from `peminjam` order by ID_Peminjam";
            ResultSet rs = st.executeQuery(sql);
            rs.last();
            int n = rs.getRow();
            Object[] dataBoxs = new Object[n + 1];
            if (n != 0) {
                rs.beforeFirst();
                int p = 0;
                dataBoxs[0] = "ID Peminjam";
                while (rs.next()) {
                    dataBoxs[p + 1] = rs.getString(1);
                    p++;
                }
                checkbox = new DefaultComboBoxModel((Object[]) dataBoxs);
                cbIdPeminjam.setModel(checkbox);
            }
        } catch (SQLException ex) {
            JOptionPane.showMessageDialog(null, ex, "Error", JOptionPane.ERROR_MESSAGE);
        }
    }

    private void getDetailPeminjaman() {
        try {
            int n = 0;
            Statement st = DataBaseConnection.getConnection().createStatement();
            String sql = "select Kode_DVD,JudulFilm,Harga,Stock,Dipinjam from `dvd/vcd` "
                    + "where Kode_DVD='" + tKodeDVD.getText() + "';";
            ResultSet rs = st.executeQuery(sql);
            rs.last();
            n = rs.getRow();
            if (n != 0) {
                rs.beforeFirst();
                while (rs.next()) {
                    tKodeDVD.setText(rs.getString(1));
                    tJudulFilm.setText(rs.getString(2));
                    tHarga.setText(rs.getString(3));
                    tStock.setText(rs.getString(4));
                    tDipinjam.setText(rs.getString(5));
                }
            } else {
                tKodeDVD.setText("");
                tJudulFilm.setText("");
                tHarga.setText("");
            }
        } catch (SQLException ex) {
            JOptionPane.showMessageDialog(null, ex, "Error", JOptionPane.ERROR_MESSAGE);
        }
    }

    private double hitungSubTotal() {
        int row = tbDetailPeminjaman.getRowCount();
        double harga = 0;
        for (int i = 0; i < row; i++) {
            harga += (Double) tbDetailPeminjaman.getValueAt(i, 2);
        }
        return harga;
    }

    private void simpanDetailPeminjaman() throws SQLException {
        int row = tbDetailPeminjaman.getRowCount();
        for (int i = 0; i < row; i++) {
            String sql = "insert into `detailpeminjaman`(noPeminjaman,Kode_DVD,JudulFilm,Harga) "
                    + "values (?,?,?,?);";
            PreparedStatement st = DataBaseConnection.getConnection().prepareStatement(sql);
            st.setString(1, tNoPeminjaman.getText());
            st.setString(2, (String) tbDetailPeminjaman.getValueAt(i, 0));
            st.setString(3, (String) tbDetailPeminjaman.getValueAt(i, 1));
            st.setDouble(4, (Double) tbDetailPeminjaman.getValueAt(i, 2));
            st.executeUpdate();
        }
    }

    private void kurangStockDVD() throws SQLException {
        int row = tbDetailPeminjaman.getRowCount();
        for (int i = 0; i < row; i++) {
            String a1 = (String) tbDetailPeminjaman.getValueAt(i, 0);
            String sql = "CALL TambahDipinjam(?);";
            PreparedStatement st = DataBaseConnection.getConnection().prepareStatement(sql);
            st.setString(1, a1);
            st.executeUpdate();
        }
    }
private void buttonTutupActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonTutupActionPerformed
    this.setVisible(false);// TODO add your handling code here:
}//GEN-LAST:event_buttonTutupActionPerformed

private void cbIdPeminjamActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cbIdPeminjamActionPerformed
    if (cbIdPeminjam.getSelectedIndex() == 0) {
        tNama.setText("");
        tTelepon.setText("");
        tAlamat.setText("");
    } else {
        try {
            Statement st = DataBaseConnection.getConnection().createStatement();
            String sql = "select Nama_peminjam,Telepon,Alamat from `peminjam` "
                    + "where ID_Peminjam='" + cbIdPeminjam.getSelectedItem().toString() + "';";
            ResultSet rs = st.executeQuery(sql);
            while (rs.next()) {
                tNama.setText(rs.getString(1));
                tTelepon.setText(rs.getString(2));
                tAlamat.setText(rs.getString(3));
            }
        } catch (SQLException ex) {
            JOptionPane.showMessageDialog(null, ex, "Error", JOptionPane.ERROR_MESSAGE);
        }
    }
}//GEN-LAST:event_cbIdPeminjamActionPerformed

private void tKodeDVDKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_tKodeDVDKeyPressed
    if (evt.getKeyCode() == 10) {
        getDetailPeminjaman();
    } else if (evt.getKeyCode() == 27) {
        getDetailPeminjaman();
    }
}//GEN-LAST:event_tKodeDVDKeyPressed

private void buttonTambahListActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonTambahListActionPerformed
    int dipinjam = Integer.parseInt(tDipinjam.getText());
    int stock = Integer.parseInt(tStock.getText());
    if (dipinjam == stock) {
        JOptionPane.showMessageDialog(null, "Tidak ada stock untuk dipinjamkan.", "Perhatian", JOptionPane.WARNING_MESSAGE);
    } else {
        try {
            DetailPeminjaman jF = new DetailPeminjaman();
            jF.setKodeDVD(tKodeDVD.getText());
            jF.setJudulFilm(tJudulFilm.getText());
            jF.setHarga(Double.parseDouble(tHarga.getText()));
            tabelModel.tambahJenisFilm(jF);
            tTotal.setText(String.valueOf(hitungSubTotal()));
        } catch (NumberFormatException ex) {
        }
    }
}//GEN-LAST:event_buttonTambahListActionPerformed

private void buttonSimpanActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonSimpanActionPerformed
    if (dcTanggalPinjam.getDate() != null || dcTanggalKembali.getDate() != null
            || tbDetailPeminjaman.getRowCount() != 0) {
        try {
            SimpleDateFormat spdt = new SimpleDateFormat(dcTanggalPinjam.getDateFormatString());
            String dt = spdt.format(dcTanggalPinjam.getDate());
            SimpleDateFormat spdt1 = new SimpleDateFormat(dcTanggalKembali.getDateFormatString());
            String dt1 = spdt1.format(dcTanggalKembali.getDate());
            String sql = "insert into `peminjaman`(noPeminjaman,ID_Operator,ID_Peminjam,tanggalPinjam,tanggalKembali,jaminan,total) "
                    + "values (?,?,?,?,?,?,?);";
            PreparedStatement st = DataBaseConnection.getConnection().prepareStatement(sql);
            st.setString(1, tNoPeminjaman.getText());
            st.setString(2, getId());
            st.setString(3, (String) cbIdPeminjam.getSelectedItem());
            st.setDate(4, java.sql.Date.valueOf(dt));
            st.setDate(5, java.sql.Date.valueOf(dt1));
            st.setString(6, (String) cbJaminan.getSelectedItem());
            st.setDouble(7, Double.parseDouble(tTotal.getText()));
            st.executeUpdate();
            simpanDetailPeminjaman();
            kurangStockDVD();
            JOptionPane.showMessageDialog(null, "Transaksi berhasil dilakukan");
        } catch (SQLException ex) {
            JOptionPane.showMessageDialog(null, ex, "Error", JOptionPane.ERROR_MESSAGE);
        }
    } else {
        JOptionPane.showMessageDialog(null, "Pastikan data tranaksi terisi semua", "Peringatan", JOptionPane.WARNING_MESSAGE);
    }
}//GEN-LAST:event_buttonSimpanActionPerformed

private void buttonCetakNotaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonCetakNotaActionPerformed
}//GEN-LAST:event_buttonCetakNotaActionPerformed

private void bBaruActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bBaruActionPerformed
    try {
        Calendar c1 = Calendar.getInstance();
        int year = c1.get(Calendar.YEAR);
        int mount = c1.get(Calendar.MONTH) + 1;
        String Time = mount + "" + year;
        Statement st = DataBaseConnection.getConnection().createStatement();
        String sql = "select * from `peminjaman`;";
        ResultSet rs = st.executeQuery(sql);
        int rec = 0;
        while (rs.next()) {
            rec = rs.getRow();
        }
        DecimalFormat df = new DecimalFormat("0000");
        DecimalFormatSymbols dfs = new DecimalFormatSymbols();
        df.setDecimalFormatSymbols(dfs);
        if (rec == 0) {
            tNoPeminjaman.setText("USD-" + Time + "-0001");
        } else {
            int numb = rec + 1;
            String _noPer = df.format(numb);
            tNoPeminjaman.setText("USD-" + Time + "-" + _noPer);
        }
        cbIdPeminjam.setSelectedIndex(0);
        dcTanggalPinjam.setDate(null);
        dcTanggalKembali.setDate(null);
        cbJaminan.setSelectedIndex(-1);
        tKodeDVD.setText("");
        tHarga.setText("");
        tJudulFilm.setText("");
        tTotal.setText("");
        tStock.setText("");
        tDipinjam.setText("");
        int row = tbDetailPeminjaman.getRowCount();
        for (int i = 0; i < row; i++) {
            tabelModel.hapusTabel(0, row);
        }
        idPeminjamComboBox();
    } catch (SQLException ex) {
        JOptionPane.showMessageDialog(null, ex, "Error", JOptionPane.ERROR_MESSAGE);
    }
}//GEN-LAST:event_bBaruActionPerformed
    private String id;
    private DefaultComboBoxModel checkbox;
    private detailPeminjamanTabelModel tabelModel;
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton bBaru;
    private javax.swing.JButton buttonCetakNota;
    private javax.swing.JButton buttonSimpan;
    private javax.swing.JButton buttonTambahList;
    private javax.swing.JButton buttonTutup;
    private javax.swing.JComboBox cbIdPeminjam;
    private javax.swing.JComboBox cbJaminan;
    private com.toedter.calendar.JDateChooser dcTanggalKembali;
    private com.toedter.calendar.JDateChooser dcTanggalPinjam;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JPanel jPanel6;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JLabel labelFormPeminjaman;
    private javax.swing.JTextField tAlamat;
    private javax.swing.JTextField tDipinjam;
    private javax.swing.JTextField tHarga;
    private javax.swing.JTextField tJudulFilm;
    private javax.swing.JTextField tKodeDVD;
    private javax.swing.JTextField tNama;
    private javax.swing.JTextField tNoPeminjaman;
    private javax.swing.JTextField tStock;
    private javax.swing.JTextField tTelepon;
    private javax.swing.JTextField tTotal;
    private javax.swing.JTable tbDetailPeminjaman;
    // End of variables declaration//GEN-END:variables
}
